home *** CD-ROM | disk | FTP | other *** search
/ Aminet 37 / Aminet 37 (2000)(Schatztruhe)[!][Jun 2000].iso / Aminet / dev / src / emog.lha / scanner.lex < prev    next >
Encoding:
Text File  |  2000-03-07  |  1.5 KB  |  66 lines

  1. %{
  2. /*
  3.  * This lex file is used to generate a simple
  4.  * scanner using lex or flex (comes with the
  5.  * GeekGadgets stuff). The resulting scanner
  6.  * separates the C-header file in a list of
  7.  * tokens, each separated by a newline.
  8.  * Each outputted line has the following format:
  9.  *
  10.  *    k######    -> The stuff after "k" is a keyword
  11.  *    i######    -> The stuff after "i" is an identifier
  12.  *    o######    -> The stuff after "o" is a sequence of special characters
  13.  *    d######    -> The stuff after "d" is a decimal number
  14.  *    h######    -> The stuff after "h" is a hexadecimal number
  15.  *
  16.  */
  17. #include <stdio.h>
  18. #define YY_MAIN
  19. int depth = 0;   /* Needed to ignore comments properly */
  20. %}
  21. CYPHER      [0-9]
  22. HEXADIGIT   [0-9a-fA-F]
  23. LETTER      [A-Z_a-z]
  24. %%
  25. ("#define"|"#ifdef"|"#endif"|"#ifndef"|"#include"|"struct") {
  26.   if( depth == 0 ) {
  27.     printf( "k%s\n", yytext );
  28.   }; /* endif */
  29. }
  30. ("\x22\x22") {
  31.   if( depth == 0 ) {
  32.     printf( "i\x22\x22\n" );
  33.   }; /* endif */
  34. }
  35. ("\x22"|"("|")"|"~"|"|"|"&"|"{"|"}"|","|";"|"*"|"<"|">"|"="|"/"|"+"|"-"|"."|"\["|"\]"|"\\") {
  36.   if( depth == 0 ) {
  37.     printf( "o%s\n", yytext );
  38.   }; /* endif */
  39. }
  40. ({LETTER})({LETTER}|{CYPHER})* {
  41.   if( depth == 0 ) {
  42.     printf( "i%s\n", yytext );
  43.   }; /* endif */
  44. }
  45. ({CYPHER})+("L")? {
  46.   if( depth == 0 ) {
  47.     printf( "d%s\n", yytext );
  48.   }; /* endif */
  49. }
  50. ("0x")({HEXADIGIT})+ {
  51.   if( depth == 0 ) {
  52.     printf( "h%s\n", yytext );
  53.   }; /* endif */
  54. }
  55. "//".*\n {
  56. }
  57. "/*" {
  58.   depth += 1;
  59. }
  60. "*/" {
  61.   depth -= 1;
  62. }
  63. ['? \n$\t#:@!] {
  64. }
  65.  
  66.